<template>
  <el-dialog title="添加商品单位" :visible.sync="dialogFormVisible">
    <el-form ref="form" :model="form"
             size="mini"
             label-width="5vw">
      <el-form-item label="单位名称" >
        <el-input v-model="form.unit"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="dialogFormVisible=false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
    import bus from "../../../bus";

    export default {
        name: "AddUnit",
      data(){
        return{
          dialogFormVisible: false,
          form: {
            unit: '',
          },
        }
      },
      methods:{
        onSubmit(){
          this.$axios
            .post('/units/add', {
              unit:this.form.unit
            }).then(resp => {
            if (resp && resp.status === 200) {
              //this.dialogFormVisible = false
              this.$emit('loadUnits');
              this.$message({
                message:this.form.unit+'添加成功',
                type:'success'
              })
            }
          })
        }
      }
    }
</script>

<style scoped>

</style>
